package cn.fay.chapter18;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class ChannelCopy {
	public static void main(String[] args) throws Exception {
		FileChannel in=new FileInputStream(new File("src/cn/fay/chapter18/Directory.java").getAbsoluteFile()).getChannel();
		FileChannel out=new FileOutputStream("out.txt").getChannel();
		ByteBuffer buffer=ByteBuffer.allocateDirect(1024);
		while((in.read(buffer))!=-1)
		{
			buffer.flip();
			out.write(buffer);
			buffer.clear();
		}
	}
}
